<?php
/**
 * Return instance of the core or its property if provided
 *
 * @param	string	$file
 * @return	string
 */
function component($xml, $compType = "component")
{
	//Start a specific component only!
	$compName = ucfirst($xml->getTag());

	//Does souch component exist?
	$res = core("File")->GetDirContentSelective("classes/structure/".$compType."s", $compName."\.class\.php");

	if(empty($res))
	{
		service("debug")->error(ucfirst($compType)." $compName doesn't exists");
	}

	service("debug")->TimerStart();

	$component = core()->NewObject("\structure\\" . $compType . "s\\$compName", $xml);

	$component->RunPreModifiers();

	$result = $component->Start();

	if ($compType == "component")
	{
		$component->RunPostModifiers($result);
		$res = $component->Complete();
	}
	else
	{
		$res = $result;
	}

	$time = service("debug")->TimerStop();

	service("debug")->LogComponent($compName, $time);

	return $res;
}